package com.singzi.leetcode.N200;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class T0139 {
    public static void main(String[] args) {
        String s = "catsandogd";
        List<String> wordDict = new ArrayList<>();
        wordDict.add("cats");
        wordDict.add("dog");
        wordDict.add("sand");
        wordDict.add("og");
        wordDict.add("and");
        wordDict.add("cat");
        Solution0139 solution0139 = new Solution0139();
        System.out.println(solution0139.wordBreak(s, wordDict));

    }
}
class Solution0139 {
    public boolean wordBreak(String s, List<String> wordDict) {
        boolean []dp = new boolean[s.length() +1];
        dp[0] = true;
        for (int i = 0; i <= s.length(); i++) {//遍历s
            for (int j = 0; j < i; j++) {
                String tempWord = s.substring(j, i);
                if (wordDict.contains(tempWord) && dp[j]) {
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[s.length()];


    }
}